package com.draemoncode.weixindb.repository;


import com.draemoncode.weixindb.domain.B_Member;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Lock;
import org.springframework.data.jpa.repository.Query;

import javax.persistence.LockModeType;

public interface B_MemberRepository extends JpaRepository<B_Member, Integer>{

    public B_Member findByName(String name);

    @Lock(LockModeType.PESSIMISTIC_WRITE)
    @Query("from B_Member where id=?1")
    public B_Member findByIdForUpdate(Integer id);

    @Lock(LockModeType.PESSIMISTIC_WRITE)
    @Query("from B_Member where name=?1")
    public B_Member findByNameForUpdate(String name);

    public Page<B_Member> findByNameLike(String name, Pageable pageable);
}
